<#assign pageTitle = "用户注册" />
<#assign pageHeader>
	<link rel="stylesheet" href="/static/css/login.css">
</#assign>
<#assign pageContent>
	<div class="body-wrap">
	<div class="third-party content-wrap">
		<div class="form-box">
			<h2 class="title">新用户注册</h2>
			<form id="registerForm">
				<div class="menu">
					<ul class="third-p-form">
						<li>
							<p class="form-title">手机号：</p>
							<input id="reg-mobile" type="text" maxlength="11" class="t-p-inp" placeholder="请输入手机号"  onkeyup="$(this).next().html('');">
							<p class="lr-tip-wrap"></p>
						</li>
						<li>
							<p class="form-title">姓名：</p>
							<input id="reg-userName" type="text" class="t-p-inp" placeholder="请输入姓名">
							<p class="lr-tip-wrap"></p>
						</li>
				<#--		<li>
							<p class="form-title">登录密码：</p>
							<input id="reg-password" type="password" maxlength="11" class="t-p-inp"  onblur="verify();" placeholder="设置登录密码" >
							<p class="lr-tip-wrap"></p>
						</li>-->
						<li>
							<p class="form-title">验证码：</p>
							<input id="reg-randomcode" type="text" maxlength="6" class="t-p-inp fl" placeholder="请输入验证码">
							<a class="code" href="javascript:void(0)">
								<img id="reg-randomcode-img" onclick="this.src='/auth/captcha/text?random='+Math.random()" alt="验证码，点击图片更换" src="/auth/captcha/text" height="41">
							</a>
							<p style="clear: both;" class="lr-tip-wrap"></p>
						</li>
						<li>
							<p class="form-title">手机短信码：</p>
							<input id="reg-mobile-code" type="text" class="t-p-inp fl" maxlength="6" placeholder="请输入手机短信码">
							<a href="javascript:void(0)" id="btn_send_reg"  onclick="sendBindingCode()" class="layui-btn layui-btn-primary">获取短信码</a>
							<p style="clear: both;" class="lr-tip-wrap"></p>
						</li>
						<li>
							<a href="javascript:void(0)"  onclick="dialogRegister()" class="layui-btn layui-btn-danger layui-btn-lg">注册新用户</a>
						</li>
					</ul>
				</div>
			</form>
		</div>
	</div>
</div>
	<script type="text/javascript">
		/*验证密码*/
		function verify() {
			if($('#reg-password').val().trim().length < 6){
				$('#reg-password').next().html('密码长度不能小于六位！');
			}
		}
		function dialogRegister() {
			/*获取手机号*/
			var mobileVal = $("#reg-mobile").val();
			/*如果手机验证开关打开*/
			if (!isMobile(mobileVal)) {//格式不正确
				$("#reg-mobile").next().html('请输入正确的手机号！');
				return;
			}
			var mobileCode = $("#reg-mobile-code").val();
			if (isEmpty(mobileCode)) {
				$("#reg-mobile-code").next().next().html('请输入手机验证码！');
				return;
			}

		/*	if ($("#reg-password").val().trim() == "") {//验证密码是否为空
				$("#reg-password").next().html('请输入密码！');
				return;
			}*/
			if ($("#reg-password").val().length < 6) {//验证密码长度
				$("#reg-password").next().html('密码长度不能小于六位！');
				return;
			}
			if (($("#reg-password").val()).indexOf(" ") != -1) {
				$("#reg-password").next().html('密码不能包含空格！');
				return false;
			}
			$.ajax({
				url: "/auth/register/create.json",
				data: {
					"mobile": $("#reg-mobile").val(),
					"password": $("#reg-password").val(),
					"userName": $("#reg-userName").val(),
					"mobileCode": $("#reg-mobile-code").val()
				},
				type: "post",
				dataType: "json",
				cache: false,
				success: function (result) {
					if (result.code === 0) {
						window.location.href = "/user/info.html";
					} else {
						return layer.msg(result.msg);
					}
				},
				error: function (error) {
					alert('系统繁忙，请稍后再操作');
				}
			});
		}
		/**发送手机验证码*/
		function sendBindingCode() {
			var mobile = $('#reg-mobile').val();
			var ranCode = $('#reg-randomcode').val();
			if (!isMobile(mobile)) {
				$("#binding_mobile").focus();
				return layer.alert("请输入正确的手机号码！");
			}
			var loading = layer.load(2, {time: 5 * 1000});
			$.ajax({
				url: '/ajax/sendCode.json',
				type: 'post', dataType: 'json',
				data: {"type":"binding","mobile": mobile , "ranCode" : ranCode},
				success: function (result) {
					if (result.code === 0) {
						var timeNum = 60; /*当点击获取验证码后设置60秒计时不可点击*/
						//设置按钮不可点击
						$("#btn_send_reg").addClass("layui-btn-disabled").attr("onclick", "").text(timeNum + "秒后可点击");
						var timeTicket = setInterval(function () {
							if (timeNum > 1) {
								timeNum--;
								$("#btn_send_reg").text(timeNum + "秒后可点击");
							} else {
								$("#btn_send_reg").removeClass("layui-btn-disabled").attr("onclick", "sendBindingCode()").text("获取短信码");
								clearInterval(timeTicket);
							}
						}, 1000);
					} else {
						return layer.alert(result.msg);
					}
				},
				error: function (e) {
					return layer.alert("send error!");
				},
				complete: function () {
					layer.close(loading);
				}
			});
		}
		/**发送手机号码*/
		function isMobile(strVal) {
			if (strVal == null || strVal === "") {
				return false;
			}
			var reg = /^1{1}[0-9]{10}$/; //验证手机正则
			return reg.test(strVal);
		}
	</script>
</#assign>
<#include "../layouts/layout.ftl">